﻿using Abp.Application.Services;
using BRMC.IntelligentCommunity.Dto;
using BRMC.IntelligentCommunity.IntelligentCommunity.Parkings;
using BRMC.IntelligentCommunity.Parkings.ParkGuards.Dto;

using Abp.Domain.Repositories;
using System.Linq;
using System.Threading.Tasks;
using Abp.Application.Services.Dto;

namespace BRMC.IntelligentCommunity.Parkings
{
    public class ParkGuardAppService : AsyncCrudAppService<
           ParkGuard,
            ParkGuardListDto,
            long,
             GetParkGuardInput,
            CreateParkGuardDto,
            UpdateParkGuard
            >
    {
     
        private readonly IRepository<ParkGuard, long> _repository;
        public ParkGuardAppService(IRepository<ParkGuard, long> repository) : base(repository)
        {

            _repository = repository;
        }


        protected override IQueryable<ParkGuard> CreateFilteredQuery(GetParkGuardInput input)
        {
            return base.CreateFilteredQuery(input)
                .Where(c => c.ParkingId == input.ParkingId);

        }

        public async Task<GetParkGuardForEdtiOutput> GetParkingForEdit(NullableIdDto input)
        {
            ParkGuard parkGuard = null;
            if (input.Id.HasValue)
            {
                parkGuard = await _repository.GetAsync(input.Id.Value);
            }

            var output = new GetParkGuardForEdtiOutput();

            output.PrakGuardEdit = parkGuard != null ? ObjectMapper.Map<PrakGuardEditDto>(parkGuard) : new PrakGuardEditDto();



     

            return output;
        }
    }
}